package com.supinfo.sun.sungamers.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.supinfo.sun.sungamers.games.CapitalFinderGame;
import com.supinfo.sun.sungamers.games.FinderGame;
import com.supinfo.sun.sungamers.games.NumberFinderGame;
import com.supinfo.sun.sungamers.gui.listeners.TryItActionListener;

/**
 * @author Liu, Bing(Locke)
 * @since 2011-6-5
 * @version 0.3
 */
public class PlayFrame extends JFrame {
	
	private FinderGame finderGame;
	private JLabel label;
	private JTextField txtField;
	private JButton btnTry;
	private ResourceBundle myBundle;
	
	public PlayFrame(FinderGame finderGame) {
		myBundle = ResourceBundle.getBundle("com.supinfo.sun.sungamers.lang.sungame");
		
		this.finderGame = finderGame;
		
		finderGame.initGame();

		this.setSize(300, 80);
		
		this.setLocationRelativeTo(null);
		
		this.setLayout(new FlowLayout());
		
		label = new JLabel();
		
		txtField = new JTextField(8);
		
		btnTry = new JButton(myBundle.getString("try"));
		
		if(finderGame != null) {
			if(finderGame instanceof NumberFinderGame) {
				this.setTitle(myBundle.getString("numberFinderGame"));
				label.setText(myBundle.getString("enterNum"));
			}
			if(finderGame instanceof CapitalFinderGame) {
				this.setTitle(myBundle.getString("capitalFinderGame"));
				label.setText(myBundle.getString("enterCity"));
			}
		}
		
		this.add(label);
		this.add(txtField);
		this.add(btnTry);
		
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		this.setVisible(true);
		
		btnTry.addActionListener(new TryItActionListener(this));
	}

	public FinderGame getFinderGame() {
		return finderGame;
	}

	public JLabel getLabel() {
		return label;
	}

	public JTextField getTxtField() {
		return txtField;
	}

	public JButton getBtnTry() {
		return btnTry;
	}
}
